﻿using System;

namespace Token.Piker.Core.Model
{
    /// <summary>
    /// 基本信息的用户
    /// </summary>
    [Serializable]
    public class AbstractUser 
    {
        public AbstractUser()
        {
        }

        /// <summary>
        /// 用户类型
        /// </summary>
        public enum ERole
        {
            /// <summary>
            /// 没有权限
            /// </summary>
            未登录 = 0,

            /// <summary>
            /// 实习编辑，可以添加、修改自己和本栏目其他编辑的新闻，不能发布和删除
            /// </summary>
            未验证 = 1,

            /// <summary>
            /// 责任编辑
            /// </summary>
            已验证 = 2,

            /// <summary>
            /// 管理员,拥有用户管理等一切权限
            /// </summary>
            系统管理员 = 4

            
        }

        public AbstractUser(string uid)
        {
            this.id = uid;
        }

        private string username;

        public string Username
        {
            get { return username; }
            set { username = value; }
        }
        private string id;

        public string Id
        {
            get { return id; }
            set { id = value; }
        }
        
        private ERole role = ERole.未登录;

        public ERole Role
        {
            get { return role; }
            set { role = value; }
        }

        #region 重写 Equals GetHashCode
        public override bool Equals(object obj)
        {
            if (obj == null)
                return false;

            if (GetType() != obj.GetType())
                return false;

            User target = (User)obj;

            if (Id != target.Id)
                return false;

            return true;
        }

        /// <summary>
        /// 生成hashCode，比较通用的做法
        /// </summary>
        /// <returns></returns>
        public override int GetHashCode()
        {
            int result = 17;  //任意素数 

            result = 31 * result + Convert.ToInt32(Id);

            return result;

        }
        #endregion
    }
}